﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Jumpton.SFA.Server.BusinessRule.MasterData;
using Jumpton.SFA.Server.BusinessRule;
using Jumpton.SFA.Server.BusinessRule.System;
public partial class masterdata_PeopleList : PageBase
{
    private Boolean ReadOnly;
    protected void Page_Load(object sender, EventArgs e)
    {
        ReadOnly = Request.QueryString.ToString().ToUpper().IndexOf("READONLY") > -1;
        this.txtHidOrg.Value = OrgHidValue;
        this.txtOrg.Text = OrgShowValue;
        if (!IsPostBack)
        {
            DataBind();
            BindDDL();
            
        }
        if (ReadOnly)
            btnAdd.Visible = false;
    }
    protected void BindDDL()
    {
        this.ddlPosition.DataSource = new DictionaryItemsManager().GetItemList(DictionaryEnum.UserPosition,MyStateManager.DomainID);
        this.ddlPosition.DataTextField = "NAME";
        this.ddlPosition.DataValueField = "DictionaryItemID";
        this.ddlPosition.DataBind();
        this.ddlPosition.Items.Insert(0, new ListItem("--所有--", ""));
    }

    private void BindPerson()
    {
        DataTable dt = PersonManager.SelectPERSONSsDynamic(
                                                                    null,
                                                                    null,
                                                                    null,
                                                                    MyStateManager.DomainID,
                                                                    txtHidOrg.Value,
                                                                    null,1
                                                                    ).Tables[0];
        PeopleCount.Text = dt.Rows.Count.ToString();
        GridPager1.DataSource = dt;
        GridPager1.GridView = GridView1;
        GridPager1.BindData();
        GridPager1.Visible = GridView1.Rows.Count > 0;
    }
    protected void btnQuery_Click(object sender, EventArgs e)
    {
        BindPerson();
       
    }

     protected void Grid_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {

            HyperLink field = e.Row.Controls[0].Controls[0] as HyperLink;
            if (field != null && ReadOnly)
            {
                field.NavigateUrl += "&READONLY";
            }
        }
       
    }

    public void GridViewToolbarUserControl1_OnGVTBSetColumnsButtonEvent(object sender, EventArgs e)
    {
        BindPerson();
    }

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        BindPerson();
    }

    protected void btnExport_Click(object sender, EventArgs e)
    {
        Response.Redirect(string.Format(@"..\ExportExcel\ExportExcel.aspx?Table=PeopleList&Name={0}&Sex={1}&Position={2}&Valid={3}",
                                                                            txtName.Text,
                                                                            ddlSex.SelectedValue,
                                                                            ddlPosition.SelectedValue,
                                                                            ddlValid.SelectedValue));
    }
}
